package weeny.pre.expression;

import prefuse.data.Schema;
import prefuse.data.Tuple;
import prefuse.data.expression.Expression;
import prefuse.data.expression.FunctionExpression;
import prefuse.data.expression.Predicate;

public class SafePredicate extends FunctionExpression implements Predicate{

	public SafePredicate(Expression exp){
		this();
		addParameter(exp);
	}
	public SafePredicate() {
		super(1);
	}

	public Class getType(Schema s) {
		return boolean.class;
	}

	@Override
	public boolean getBoolean(Tuple t) {
		if ( paramCount() == 1 ) {
			try {
				return param(0).getBoolean(t);	
			} catch (Exception e) {
				return false;
			}
		}
		missingParams();
		return true;
	}
	
	public String getName() {
		return "SAFE";
	}
}
